
package dialogs;

import main.DialogGridCreation;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import main.GlobalMethods;
import main.Icons;

/**
 *
 * @author Raed Shomali
 */
public class EAFDialog extends JDialog implements ActionListener
{
    JTabbedPane tabs = new JTabbedPane();

    private JPanel productPanel = new JPanel();
    private JPanel platformPanel = new JPanel();
    private JPanel personnelPanel = new JPanel();
    private JPanel projectPanel = new JPanel();
    private JPanel userPanel = new JPanel();
    
    private String[] productNames = new String[]
    {
        "RELY" , "DATA" , "DOCU" , "CPLX" , "RUSE"
    };

    private String[] platformNames = new String[]
    {
        "TIME" , "STOR" , "PVOL"
    };

    private String[] personnelNames = new String[]
    {
        "ACAP" , "APEX" , "PCAP" , "PLEX" , "LTEX" , "PCON"
    };

    private String[] projectNames = new String[]
    {
        "TOOL" , "SCED" , "SITE" , "TEST"
    };

    private String[] userNames = new String[]
    {
        "USR1" , "USR2"
    };

    private String[] ratings = new String[]
    {
        "VLO" , "LO" , "NOM" , "HI" , "VHI" , "XHI"
    };

    private JTextField[][] productFields = new JTextField[ productNames.length ][ ratings.length ];
    private JTextField[][] platformFields = new JTextField[ platformNames.length ][ ratings.length ];
    private JTextField[][] personnelFields = new JTextField[ personnelNames.length ][ ratings.length ];
    private JTextField[][] projectFields = new JTextField[ projectNames.length ][ ratings.length ];
    private JTextField[][] userFields = new JTextField[ userNames.length ][ ratings.length ];

    JButton applyButton = new JButton( "Apply" ) ;
    JButton resetButton = new JButton( "Reset" ) ;
    JButton closeButton = new JButton( "Close" ) ;
    
    public EAFDialog( JFrame frame )
    {
        super( frame );

        this.setModal( true );

        this.setTitle( "Effort Adjustment Factors" );

        GlobalMethods.updateStatusBar( "Done." );

        // Buttons
        applyButton.addActionListener( this ) ;
        resetButton.addActionListener( this ) ;
        closeButton.addActionListener( this ) ;
        
        applyButton.setFocusable( false ) ;
        resetButton.setFocusable( false ) ;
        closeButton.setFocusable( false ) ;
        
        applyButton.setIcon( Icons.SAVE_ICON  ) ;
        resetButton.setIcon( Icons.RESET_ICON  ) ;
        closeButton.setIcon( Icons.CLOSE_ICON  ) ;
        
        // Text Fields
        for ( int i = 0 ; i < productNames.length ; i++ )
        {
            for ( int j = 0 ; j < ratings.length ; j++ )
            {
                productFields[ i ][ j ] = new JTextField() ;
                productFields[ i ][ j ].setText( j + "" );
            }
        }
        
        for ( int i = 0 ; i < platformNames.length ; i++ )
        {
            for ( int j = 0 ; j < ratings.length ; j++ )
            {
                platformFields[ i ][ j ] = new JTextField() ;
                platformFields[ i ][ j ].setText( j + "" );
            }
        }
        
        for ( int i = 0 ; i < personnelNames.length ; i++ )
        {
            for ( int j = 0 ; j < ratings.length ; j++ )
            {
                personnelFields[ i ][ j ] = new JTextField() ;
                personnelFields[ i ][ j ].setText( j + "" );
            }
        }
        
        for ( int i = 0 ; i < projectNames.length ; i++ )
        {
            for ( int j = 0 ; j < ratings.length ; j++ )
            {
                projectFields[ i ][ j ] = new JTextField() ;
                projectFields[ i ][ j ].setText( j + "" );
            }
        }
        
        for ( int i = 0 ; i < userNames.length ; i++ )
        {
            for ( int j = 0 ; j < ratings.length ; j++ )
            {
                userFields[ i ][ j ] = new JTextField() ;
                userFields[ i ][ j ].setText( j + "" );
            }
        }
        
        // Tabs
        addTab( "Project" , productPanel , productNames , ratings , productFields );
        addTab( "Platform" , platformPanel , platformNames , ratings , platformFields );
        addTab( "Personnel" , personnelPanel , personnelNames , ratings , personnelFields );
        addTab( "Project" , projectPanel , projectNames , ratings , projectFields );
        addTab( "User Defined" , userPanel , userNames , ratings , userFields );

        // Panel
        JPanel southPanel = new JPanel();
        southPanel.add( applyButton ) ;
        southPanel.add( resetButton ) ;
        southPanel.add( closeButton ) ;
        
        // GUI
        this.setLayout( new BorderLayout() );
        this.add( tabs );
        this.add( southPanel , BorderLayout.SOUTH ) ;

        this.setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
        this.setLocation( this.getOwner().getX() + 100 , this.getOwner().getY() + 100 );
        this.setResizable( false );
        this.setSize( 450 , 330 );
        this.setVisible( true );
    }

    private void addTab( String tabName , JPanel container , String[] driverNames , String[] ratings , JTextField[][] field )
    {
        tabs.addTab( tabName , container );
        DialogGridCreation.createTextFieldGrid( container , driverNames , ratings , field );
    }

    public void actionPerformed( ActionEvent e )
    {
        if( e.getSource() == applyButton )
        {
        }
        else if( e.getSource() == resetButton )
        {
        }
        else
        {
            // Free Resources ... Close Window
            this.dispose() ;
        }
    }

}
